package com.acme.spring.config;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
public class EmailBeans {
	@Bean 
	public JavaMailSender mailSender() { 
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); 
		mailSender.setHost("smtp.gmail.com"); 
		mailSender.setPort(587); 
		mailSender.setUsername("rentflixautosup"); 
		mailSender.setPassword("rentdoor155"); 
		Properties properties = new Properties(); 
		properties.setProperty("mail.smtp.auth", "true"); 
		properties.setProperty("mail.smtp.starttls.enable", "true"); 
		mailSender.setJavaMailProperties(properties); 
		return mailSender;
	}
	
	@Bean(name = "contactUsEmail")
	public SimpleMailMessage contactUsEmail() {
	SimpleMailMessage customEmail = new SimpleMailMessage();
	customEmail.setFrom("rentflixautosup@gmail.com");
	customEmail.setTo("jmorgan@eaglecrk.com");
	customEmail.setSubject("A user has submitted a contact us request.");
	customEmail.setText(
			"Contact us information\n\n" +
			"First Name: %s\n" +
			"Last Name: %s\n" +
			"Address:\n" +
			"%s\n%s\n%s, %s %s\n" +
			"Email Address: %s\n" +
			"Phone Number: %s\n" +
			"Best Time to Call: %s\n" +
			"Age: %s\n"
			);
	return customEmail;
	}
	
	@Bean(name = "claimEditedEmail")
	public SimpleMailMessage claimEditedEmail() {
	SimpleMailMessage customEmail = new SimpleMailMessage();
	customEmail.setFrom("rentflixautosup@gmail.com");
	customEmail.setSubject("AcmeClaims notification: Your claim has been edited.");
	customEmail.setText(
			"Dear %s,\n\n" +
			"This is to inform you that claim %s has been edited and submitted for review.\n\n" +
			"Attached is a copy of your edited claim.\n\n" +
			"Please do not respond to this email.");
	return customEmail;
	}
	
	@Bean(name = "claimCreatedEmail")
	public SimpleMailMessage claimCreatedEmail() {
	SimpleMailMessage customEmail = new SimpleMailMessage();
	customEmail.setFrom("rentflixautosup@gmail.com");
	customEmail.setSubject("AcmeClaims notification: Your claim has been submitted.");
	customEmail.setText(
			"Dear %s,\n\n" +
			"Your claim has been succesfully edited and submitted.\n\n" +
			"Your claim number is: %s\n\n" +
			"Attached is a copy of your submitted claim.\n\n" +
			"Please do not respond to this email.");
	return customEmail;
	}
	
	@Bean(name = "claimApprovedEmail")
	public SimpleMailMessage claimApprovedEmail() {
	SimpleMailMessage customEmail = new SimpleMailMessage();
	customEmail.setFrom("rentflixautosup@gmail.com");
	customEmail.setSubject("AcmeClaims notification: Your claim has been approved!");
	customEmail.setText(
			"Dear %s,\n\n" +
			"This is to inform you that claim number %s has been approved!\n\n" +
			"A check from your insurance company will be mailed \"promptly\".\n\n" +
			"Please do not respond to this email.");
	return customEmail;
	}
	
	@Bean(name = "claimDeniedEmail")
	public SimpleMailMessage claimDeniedEmail() {
	SimpleMailMessage customEmail = new SimpleMailMessage();
	customEmail.setFrom("rentflixautosup@gmail.com");
	customEmail.setSubject("AcmeClaims notification: Your claim has been denied!");
	customEmail.setText(
			"Dear %s,\n\n" +
			"Unforunately, claim number %s has been denied for the following reason:\n\n" +
			"%s\n\n" +
			"If you would like to review or resubmit this claim, please visit the following link:\n\n" +
			"%s\n\n" +
			"Please do not angrily respond to this email, your gripe is not with us.");
	return customEmail;
	}
	
	@Bean(name = "accountCreatedEmail")
	public SimpleMailMessage accountCreatedEmail() {
	SimpleMailMessage customEmail = new SimpleMailMessage();
	customEmail.setFrom("rentflixautosup@gmail.com");
	customEmail.setSubject("AcmeClaims notification: Your account has been created!");
	customEmail.setText(
			"Dear %s,\n\n" +
			"Thank you for creating an account! Visit the following link to view/change your account details:\n\n" +
			"%s\n\n" +
			"Please do not respond to this email.");
	return customEmail;
	}
	
	@Bean(name = "accountDisabledEmail")
	public SimpleMailMessage accountDisableEmail() {
	SimpleMailMessage customEmail = new SimpleMailMessage();
	customEmail.setFrom("rentflixautosup@gmail.com");
	customEmail.setSubject("AcmeClaims notification: Your account has been disabled!");
	customEmail.setText(
			"Dear %s,\n\n" +
			"For some reason, one of our administrators decided to disable your account!\n\n" +
			"Feel free to create a new account, or contact customer support to have your account re-enabled.\n\n" +
			"Please do not respond to this email.");
	return customEmail;
	}
	
	@Bean(name = "accountEnabledEmail")
	public SimpleMailMessage accountEnabledEmail() {
	SimpleMailMessage customEmail = new SimpleMailMessage();
	customEmail.setFrom("rentflixautosup@gmail.com");
	customEmail.setSubject("AcmeClaims notification: Your account has been disabled!");
	customEmail.setText(
			"Dear %s,\n\n" +
			"Congratulations, your account has been re-enabled!\n\n" +
			"If you did something wrong, we forgive you, otherwise sorry for the mistake!\n\n" +
			"Please do not respond to this email.");
	return customEmail;
	}
}
